package com.bigdata.controller;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

// 李文义
@Controller
@RequestMapping("/order")
public class ControllerTest {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    @RequestMapping("/placeOrder")
    public String placeOrder(){
        return "placeOrder";
    }

    @RequestMapping("/waitOrder")
    public String waitOrder(){
    //将订单放入exchange.order队列
        rabbitTemplate.convertAndSend("exchange.order","order","赶快付款，10s");
        return "waitOrder";
    }

    @RequestMapping("/payfor")
    public String payfor() {
        // 消费订单
        String str = (String) rabbitTemplate.receiveAndConvert("queue.order");
        System.out.println(str);// 赶快付款，5s

        if (!"".equals(str) || null != str){
            return "successOrder";
        }else {
            return dxl() ;
        }

    }

    public String dxl() {
        // 消费订单
        String str = (String) rabbitTemplate.receiveAndConvert("queue.order.dlx");

            return "timeoutPage";
    }

}
